const app = getApp();
Page({
	img_click:function(){
			wx.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success (res) {
						const tempFilePaths = res.tempFilePaths
					}
			})
	},
  data:{
    upImg:"",
		g_iphone: '',
  },
  onLoad:function(){
  },
	onReady:function () {
			app.SystemInfo(this)
	},
  onUpload:function(){
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths
        wx.uploadFile({
          url: app.apiDomain+'index.php?c=user&a=upload', // 仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'image',
          formData: {
            user: 'test'
          },
          success(res) {
            var data = JSON.parse(res.data);
            wx.setStorageSync('imgPath', data.data);
            that.setData({
              upImg: app.resourceDomain + data.data
            });
						console.log(that.upImg);
            // do something
          },
          fail: function (res) {
            app.request(app.apiDomain + "index.php?c=user&a=uploadFail&type=dailyupload&res=" + JSON.stringify(res));

          }
        })
      }, 
      fail: function (res) {
        app.request(app.apiDomain + "index.php?c=user&a=uploadFail&type=dailychoose&res=" + JSON.stringify(res));
      }
    })
  },
  formSubmit: function (e) {
			// console.log(e.detail);
			wx.showLoading({
				title: '发表中',
			});
			app.request(app.apiDomain + "index.php?c=user&a=writedaily", {
				img: wx.getStorageSync('imgPath'),
				content: e.detail.value.content
			}, function (res) {
					wx.navigateTo({
						url: '../Ranking/personal',
					});
			});
  },
  onShareAppMessage: function () {
    return app.onShareAppMessage();
  }  
})



